//
//  CountViewController.m
//  collection-proto3
//
//  Created by Robert England on 10/24/10.
//  Copyright 2010 Transylvania University. All rights reserved.
//

#import "CountViewController.h"


@implementation CountViewController

//RE::24Oct2010

@synthesize item, location, count;

-(id)init {
	[super initWithNibName:nil bundle:nil];
	
	UIBarButtonItem *bbi;
	bbi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
														target:self
														action:@selector(update:)];
	[[self navigationItem] setRightBarButtonItem:bbi];
	[bbi release];
	
	[self setTitle:@"Update Count"];
	
	return self;
}

-(id)initWithNibName:(NSString *)n bundle:(NSBundle *)b {
	return [self init];
}

-(void)updateInterface { //RE:: misspelled in Big Nerd bk! p 371
	NSString *prompt = [NSString stringWithFormat:@"%@: %@",
						[item valueForKey:@"label"],
						[location valueForKey:@"label"]];
	[promptField setText:prompt];
	[numberField setText:[count stringValue]];
}
//::RE

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/
//RE::24Oct2010
-(void)viewDidLoad {
	[super viewDidLoad];
	[self updateInterface];
	[numberField becomeFirstResponder];
}
//::RE

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
//RE::24Oct2010
	[numberField release];
	numberField = nil;
	[promptField release];
	promptField = nil;
//::RE
}

//RE::24Oct2010
#pragma mark Actions

-(IBAction)update:(id)sender {
	NSString *countString = [numberField text];
	int countInt = [countString intValue];
	[self setCount:[NSNumber numberWithInt:countInt]];
	[[self navigationController] popViewControllerAnimated:YES];
}

-(IBAction)cancel:(id)sender {
	[self setCount:nil];
	[[self navigationController] popViewControllerAnimated:YES];
}
//::RE

- (void)dealloc {
	//RE::24Oct2010
	[numberField release];
	[promptField release];
	[count release];
	[item release];
	[location release];
	//::RE
    [super dealloc];
}


@end
